/* var color = ["red", "blue", "yellow", "green", "orange", "pink", "grey"];
let iterator =  color[Symbol.iterator]();
console.log(iterator);


console.log("hello");
console.log(iterator.next().value);
console.log(iterator.next().key);
console.log(iterator.next().value);

let aEntires = color.entries();
console.log(aEntires);
console.log(aEntires.next().value);
console.log(aEntires.next().value); */


//arr.push()
/* function addLastPositin(arr, ...items){
    if(!arr){
        return;    //undefined
    }else if(!items.length){
        return;
    }else{
        for(let i = 0; i < items.length; ++i){
            arr[arr.length] = items[i]
        }
        return;
    }

} 
var arr = [1, 2, 3, 4]
var arr1 = addLastPositin(arr, 5, 6);
for(let i = 0; i < arr1.length; ++i){
    console.log(arr1[i]);
}
console.log(arr);   */     //arr已经改变，指向arr的地址，修改的是arr中的值

//arr.unshift()

/* function insertFirstPosition1(arr, ...items){
    if(!arr){
        return;
    }else if(!items.length){
        return;
    }else{
        for(let i = 0; i < arr.length; ++i){
            items[items.length] = arr[i];
        }
    
        /* console.log(arguments);
        console.log(items); */     //items改变了，arguments没有改变

        /* for(let i = 0; i < items.length; ++i){
            arr[i] = items[i];
        }
        return;
    }
}
var arr = [1, 2, 3, 4, 5];
insertFirstPosition(arr, 0, 9);
console.log(arr); */
var arr = [1,2, 3, 4, 5];
function insertFirstPosition2(arr, ...items){
    if(!(arr&&items.length)){
        return;
    }else{
        let Len = arr.length;
        let len = items.length;
            for(let j = Len - 1; j >= 0; --j){
                arr[j + len] = arr[j]; 
                console.log(`${i}----${j}----${arr[j]}`);
                /* console.log(arr[j+i]);
                console.log("----" + j+i); */
            }
            for(let i = len - 1; i >= 0; --i){
                arr[i] = items[i];
            }
            
        
        return;
    }
}

insertFirstPosition2(arr, 9, 0);
console.log(arr);